Сообщение от mariocarver
|
Необходимо сделать, что данный код выполнялся каждые 5 секунд с помощью setInterval:
|
Может воспользоваться setInterval?
топа того
<html>
<head>
</head>
<body>
<div id="foo"></div>
<script>
f=function(){
if(typeof(xhr)=='undefined')
{
xhr = new XMLHttpRequest
}
xhr.open('GET', '/foo', true);
xhr.onload = function() {
document.getElementById("foo").innerHTML = this.responseText;
}
xhr.onerror = function() {
document.getElementById("foo").innerHTML = "Error";
}
xhr.send('');
}
setInterval(f, 1000)
</script>
</body>
</html>